package com.gitee.wsl.security.rbac

import com.gitee.wsl.struct.category.CategoryItemWarp

open class SubjectPermission(val subject: Subject, val permissionList: MutableList<Permission> = mutableListOf()){}

class SubjectPermissionCategory(data: SubjectPermission): CategoryItemWarp(data){
    companion object{
        val ROOT_GROUP = SubjectPermissionCategory(SubjectPermission(Subject.DEFAULT))
    }
}


interface SubjectPermissionScope{

    fun grantAll()

    fun disableAll()

    fun copyFrom(ruleName:String)

    fun copyFromParent()

    fun grant(vararg permission:String)

    fun unGrant(vararg permission:String)
}

open class SubjectPermissionScopeImp: SubjectPermissionScope {

    var isAbleAll=false

    var isDisableAll=false

    var copyFromParent=false

    var baseRuleName:String?=null

    var grantPermissionList:List<String>?=null

    var unGrantPermissionList:List<String>?=null

    override fun grantAll() {
        isAbleAll=true
    }

    override fun disableAll() {
        isDisableAll=true
    }

    override fun copyFrom(ruleName: String) {
        baseRuleName=ruleName
    }

    override fun copyFromParent() {
        copyFromParent=true
    }

    override fun grant(vararg permission: String) {
        grantPermissionList=permission.asList()
    }

    override fun unGrant(vararg permission: String) {
        unGrantPermissionList=permission.asList()
    }

}